local tieji = fk.CreateSkill {

  name = "joy_mou__tieji",

  tags = {  },

}



tieji:addEffect(fk.TargetSpecified, {
  name = "joy_mou__tieji",
  anim_type = "offensive",
  events = {fk.TargetSpecified},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(tieji.name) and data.to ~= player.id and
      data.card.trueName == "slash"
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:notifySkillInvoked(player, tieji.name)
    player:broadcastSkillInvoke("mou__tieji", 1)
    local to = room:getPlayerById(data.to)
    data.disresponsive = true
    room:addPlayerMark(to, "@@tieji-turn")
    room:addPlayerMark(to, MarkEnum.UncompulsoryInvalidity .. "-turn")
    local choices = U.doStrategy(room, player, to, {"tieji-zhiqu","tieji-raozheng"}, {"tieji-chuzheng","tieji-huwei"}, tieji.name, 1)
    local win = true
    if choices[1] == "tieji-zhiqu" and choices[2] ~= "tieji-chuzheng" then
      player:broadcastSkillInvoke("mou__tieji", 2)
      if not to:isNude() then
        local card = room:askForCardChosen(player, to, "he", tieji.name)
        room:obtainCard(player, card, false, fk.ReasonPrey)
      end
    elseif choices[1] == "tieji-raozheng" and choices[2] ~= "tieji-huwei" then
      player:broadcastSkillInvoke("mou__tieji", 3)
      player:drawCards(2, tieji.name)
    else
      win = false
      player:broadcastSkillInvoke("mou__tieji", 4)
    end
    if win then
      room:addPlayerMark(player, MarkEnum.SlashResidue.."-turn")
      if not player:isKongcheng() and #room:askForDiscard(player, 1, 1, false, tieji.name, true, ".", "#joy_mou__tieji-discard") > 0 then
        local ids = room:getCardsFromPileByRule("slash")
        if #ids > 0 then
          room:moveCardTo(ids, Card.PlayerHand, player, fk.ReasonPrey, tieji.name)
        end
      end
    end
  end,
})

return tieji